package com.xuwang.controller;

import com.xuwang.pojo.Sale;
import com.xuwang.service.impl.SaleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 聚餐记录表(Sale)表控制层
 *
 * @author abaaba
 * @since 2021-09-20 16:47:06
 * @version 1.0
 */
@RestController
@RequestMapping("/sale")
@Api(value = "聚餐记录表(Sale)管理",tags = "聚餐记录表(Sale)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class SaleController {
    /**
     * 服务对象
     */
    @Resource
    private SaleServiceImpl saleServiceImpl;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageZF", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "没也多少条",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "saleTypeId",value = "销售类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "starTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "companyName",value = "企业名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageZF(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,
                                             Integer saleTypeId,
                                             String companyName, String  starTime, String endTime ,
                                             @Autowired HttpServletRequest request) {
        return this.saleServiceImpl.selectForPage(1,index, page,saleTypeId,starTime,endTime,companyName,request);
    }
    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageQY", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "没也多少条",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "saleTypeId",value = "销售方式",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "starTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
    })
    public Map<String, Object> selectForPageQY(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,
                                               Integer saleTypeId,String  starTime, String endTime ,
                                               @Autowired HttpServletRequest request) {
        return this.saleServiceImpl.selectForPage(1,index, page,saleTypeId,starTime,endTime,null,request);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个**的接口",notes = "通过主键查询一个**的接口",httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.saleServiceImpl.selectById(id);
    }

    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param sale 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个**的接口",notes = "根据完整记录新增一个**的接口",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "sale",value = "pojo模型",required = true) Sale sale,
                                      @Autowired HttpServletRequest request) {
        return this.saleServiceImpl.insert(sale,request);
    }

}